package server

import (
	"fmt"
	"net"
)

func NewServer(address string, TCPFunc func(*net.TCPConn)) {

	listen, err := net.Listen("tcp4", address)

	if err != nil {
		fmt.Println("Start IM Server Failed", err.Error())
		return
	}

	tcpListener, ok := listen.(*net.TCPListener)

	if !ok {
		fmt.Println("listen error")
		return
	}

	for {
		tcpConn, err := tcpListener.AcceptTCP()
		if err != nil {
			fmt.Printf("tcpConn error occurred, %v", tcpConn)
			break
		}
		TCPFunc(tcpConn)
	}

}
